<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>简化合并修复</title>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <style>
        body { font-family: Arial, sans-serif; padding: 20px; }
        .result { margin: 10px 0; padding: 10px; border-radius: 5px; }
        .success { background-color: #d4edda; color: #155724; }
        .error { background-color: #f8d7da; color: #721c24; }
        .info { background-color: #d1ecf1; color: #0c5460; }
        button { padding: 10px 20px; margin: 5px; cursor: pointer; }
        pre { background-color: #f8f9fa; padding: 10px; border-radius: 5px; overflow-x: auto; }
    </style>
</head>
<body>
    <h1>VideoWeb2 上传问题修复工具</h1>
    
    <div class="info">
        <h3>当前问题：</h3>
        <p>文件 137649199_da2-1-192.mp4 分片不完整，导致合并失败出现500错误</p>
        <p>文件哈希: 7dc42c7d9e040406304698531be0b32936117c0d5e7aac94c6c28cdffeebddad</p>
    </div>

    <h3>解决方案选择：</h3>
    
    <div>
        <h4>方案1：直接合并（推荐，如果已修复数据库）</h4>
        <button onclick="directMerge()">直接合并现有分片</button>
        <div id="directResult"></div>
    </div>

    <div>
        <h4>方案2：重新开始上传</h4>
        <button onclick="cancelUpload()">清除上传状态</button>
        <div id="cancelResult"></div>
        <p>然后返回 <a href="/upload.html">上传页面</a> 重新上传文件</p>
    </div>

    <div>
        <h4>方案3：检查状态</h4>
        <button onclick="checkStatus()">检查当前状态</button>
        <div id="statusResult"></div>
    </div>

    <h3>修复步骤：</h3>
    <ol>
        <li><strong>首先</strong>：在MySQL中执行 temp_fix_merge.sql 修复数据库状态</li>
        <li><strong>然后</strong>：点击上面的"直接合并现有分片"按钮</li>
        <li><strong>如果失败</strong>：选择"清除上传状态"后重新上传</li>
    </ol>

    <script>
        const fileHash = '7dc42c7d9e040406304698531be0b32936117c0d5e7aac94c6c28cdffeebddad';

        async function directMerge() {
            const resultDiv = document.getElementById('directResult');
            resultDiv.innerHTML = '<div class="info">正在合并...</div>';
            
            try {
                const response = await axios.post('/api/upload/merge', {
                    fileHash: fileHash,
                    fileName: '137649199_da2-1-192.mp4',
                    totalChunks: 25,
                    fileSize: 51973319,
                    title: 'Test Video',
                    description: 'Fixed upload'
                }, {
                    withCredentials: true
                });
                
                resultDiv.innerHTML = `
                    <div class="success">
                        <h4>合并成功！</h4>
                        <pre>${JSON.stringify(response.data, null, 2)}</pre>
                    </div>
                `;
            } catch (error) {
                resultDiv.innerHTML = `
                    <div class="error">
                        <h4>合并失败</h4>
                        <p><strong>状态码:</strong> ${error.response?.status}</p>
                        <p><strong>错误信息:</strong></p>
                        <pre>${JSON.stringify(error.response?.data || error.message, null, 2)}</pre>
                    </div>
                `;
            }
        }

        async function cancelUpload() {
            const resultDiv = document.getElementById('cancelResult');
            resultDiv.innerHTML = '<div class="info">正在清除...</div>';
            
            try {
                const response = await axios.delete(`/api/upload/cancel/${fileHash}`, {
                    withCredentials: true
                });
                
                resultDiv.innerHTML = `
                    <div class="success">
                        <h4>清除成功！</h4>
                        <pre>${JSON.stringify(response.data, null, 2)}</pre>
                        <p>现在可以返回上传页面重新上传文件了。</p>
                    </div>
                `;
            } catch (error) {
                resultDiv.innerHTML = `
                    <div class="error">
                        <h4>清除失败</h4>
                        <pre>${JSON.stringify(error.response?.data || error.message, null, 2)}</pre>
                    </div>
                `;
            }
        }

        async function checkStatus() {
            const resultDiv = document.getElementById('statusResult');
            resultDiv.innerHTML = '<div class="info">正在检查...</div>';
            
            try {
                const response = await axios.get(`/api/upload/status/${fileHash}`, {
                    withCredentials: true
                });
                
                resultDiv.innerHTML = `
                    <div class="success">
                        <h4>状态检查成功</h4>
                        <pre>${JSON.stringify(response.data, null, 2)}</pre>
                    </div>
                `;
            } catch (error) {
                resultDiv.innerHTML = `
                    <div class="error">
                        <h4>状态检查失败</h4>
                        <pre>${JSON.stringify(error.response?.data || error.message, null, 2)}</pre>
                    </div>
                `;
            }
        }

        // 页面加载时自动检查状态
        window.onload = function() {
            checkStatus();
        };
    </script>
</body>
</html> 